package core;

import gfx.Drawable;
import gfx.ImageLoader;
import gfx.Tickable;
import gfx.tiles.Tile;
import gfx.tiles.TileGraphics;
import gfx.tiles.TileRenderer;
import gui.Button;
import gui.DropDownMenu;
import gui.GUI;
import gui.GUIkeyListener;
import gui.GUImouseListener;
import input.Keyboard;
import input.Mouse;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javax.swing.JFrame;

import modes.Mode;
import objects.Damageable;
import objects.Mine;
import objects.Robot;
import sfx.SoundManager;

import comm.Server;

/**
 * 
 * The main class with the game loop, which handles the rendering of the world and the
 * logic of the world plus some graphical functions like a minimap. 
 * This is the start class of the program.
 * 
 * @author lueko.voss
 * 
 */
public class Main extends Canvas implements Runnable {
	
    private static final long serialVersionUID = 1L;
    
    private boolean running = false;
    private int FRAME_CAP = 120;        //how many frames per second
    private int UPDATE_CAP = 60;        //how many ticks/updates per second
    
    private double frameTime;
	private double ns;
    
    private static ArrayList<Drawable> drawables = new ArrayList<Drawable>();   //graphical objects to render
    private static ArrayList<Tickable> tickables = new ArrayList<Tickable>();   //objects with logical operations to update
    
    public static final int WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width, HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;		//size of the canvas
    public static final boolean SOUND_ACTIVE = true;
    
    private BufferedImage originalMinimapImage;
    private BufferedImage image;
    private JFrame frame;
    private BufferStrategy bs;
    private String title;
    
    public static Mode mode;
    
	public static Server server;
    
    public static ImageLoader imageLoader = new ImageLoader();
    public static BufferedImage[][] tanks = imageLoader.splitImageMap(
    		imageLoader.load("/gfx/MulticolorTanks.png"), 8, 8, 32, 32);
    public static BufferedImage[][] tankGuns = imageLoader.splitImageMap(
    		imageLoader.load("/gfx/MulticolorCannons.png"), 8, 8, 32, 32);
    public static BufferedImage[][] explosion = imageLoader.splitImageMap(
    		imageLoader.load("/gfx/NewExplosion.png"), 5, 3, 96, 96);
    
    public static int worldWidth, worldHeight;		//in tile coordinates
    public static Vector2 mapPos;                   //the world coordinates
    
    private boolean mouseDown;
    private boolean mouseDownMinimap;
    private boolean mouseDownMap;

	private Vector2 minimapPos;
	private float scale = 1;
	public static float zoom = 1;
    
    private boolean left, right, up, down;
    
    private static final int NUM_PLUS = 107;
    private static final int NUM_MINUS = 109;
    
    public static int selectedRobot = -1;
    
    private DropDownMenu stdDDmenu = new DropDownMenu();
    
    public static boolean minesEnabled = true;
    public static Button minesButton;
    
    //Nick
    public static SoundManager soundManager = new SoundManager();
    
    public static GUI gui = new GUI();
    public static GUIkeyListener guiKeyListener = new GUIkeyListener();
    public static GUImouseListener guiMouseListener = new GUImouseListener();
    //-
    
    /**
     * Sets the title of the window initializes the program and starts it.
     * 
     * @param title Window title.
     */
    public Main(String title) {
        this.title = title;

        init();
    }
    
    /**
     * Creates a new main object with the title "Robots".
     * 
     * @param args unused
     */
    public static void main(String[] args) {
    	new Main("Robots");
    }
    
    /**
     * Initializes main functions and variables.
     */
    private void init() {
        image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        setPreferredSize(new Dimension(WIDTH, HEIGHT));
        
        //adding listeners to the canvas
        Keyboard keyboard = new Keyboard();
        Mouse mouse = new Mouse();
        addKeyListener(keyboard);
        addMouseListener(mouse);
        addMouseMotionListener(mouse);
        
        //Nick
        addKeyListener(guiKeyListener);
        addMouseListener(guiMouseListener);
        addMouseMotionListener(guiMouseListener);
        
        initDropDownMenus();
        //-
        
        mouse = new Mouse();
        addMouseListener(mouse);
        addMouseMotionListener(mouse);
        addMouseWheelListener(mouse);
        
        frame = new JFrame(title);
        mapPos = new Vector2(0, 0);
        
//        loadMap("/gfx/newMap.png");
        loadMap("/gfx/classMap.png");
        addTiles();
        
        left = false;
        right = false;
        up = false;
        down = false;
        
        minimapPos = new Vector2(2, 2);
        mouseDown = false;
        mouseDownMinimap = false;
        mouseDownMap = false;
        
        frameTime = 1.0 / FRAME_CAP;        //time per frame
        ns = 1000000000.0 / UPDATE_CAP;     //time per tick
        
        //setting up frame attributes
        frame.setResizable(false);
        frame.add(this);
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setIconImage(imageLoader.load("/gfx/RobotWorldIcon.png"));
        frame.setVisible(true);
        
        requestFocus();
        
        mode = new Mode(2);
        
        start();
    }
    
    private void initDropDownMenus(){
    	stdDDmenu.addToMenu(new Button("Place Decoy") {
    		@Override
    		public void trigger() {
    			Robot robot = new Robot(new Vector2((mapPos.x) * Main.zoom + stdDDmenu.getX() / Main.zoom, (mapPos.y) * Main.zoom + stdDDmenu.getY() / Main.zoom), 0d, (int)(Math.random() * 7), "Decoy", null);
    			tickables.add(robot);
    			drawables.add(robot);
    		}
    	});
    	stdDDmenu.addToMenu(new Button("Place Mine") {
    		@Override
    		public void trigger() {
    			System.out.println(mapPos + " : " + Main.zoom + " : " + stdDDmenu.getX() + ":" + stdDDmenu.getY());
    			System.out.println(((mapPos.x) * Main.zoom + stdDDmenu.getX() / Main.zoom) + " : " + ((mapPos.y) * Main.zoom + stdDDmenu.getY() / Main.zoom));
    			System.out.println();
    			Mine mine = new Mine(new Vector2((mapPos.x) * Main.zoom + stdDDmenu.getX() / Main.zoom, (mapPos.y) * Main.zoom + stdDDmenu.getY() / Main.zoom));
    			tickables.add(mine);
    			drawables.add(mine);
    		}
    	});
    	stdDDmenu.addToMenu(minesButton = new Button("Disable Mines") {
    		@Override
    		public void trigger() {
    			minesEnabled ^= true;
    			name = minesEnabled ? "Disable Mines" : "Enable Mines";
    		}
    	});
    }
    
    /**
     * Creates new tiles and adds them to the ArrayList Tile.tiles.
     */
    private void addTiles() {
//        new Tile(TileGraphics.sand, 0xffe9ff87, false, true);
//        new Tile(TileGraphics.grass, 0xff00ff00, false, true);

        new Tile(TileGraphics.grass, 0xff00ff00, Tile.AIR);
        new Tile(TileGraphics.sand, 0xffc4c62b, Tile.AIR);
        new Tile(TileGraphics.water, 0xff0000ff, Tile.WATER);
        new Tile(TileGraphics.stone, 0xff8a8a8a, Tile.AIR);
        new Tile(TileGraphics.wall, 0xff000000, Tile.SOLID);
    }
    
    /**
     * Starts the thread to run the run method.
     * Creates a new sever.
     */
    public synchronized void start() {
        Thread th = new Thread(this);
        th.start();
    	server = new Server();
    }
    
    /**
     * Handles the rendering and ticking of the program.
     * 
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() {
    	running = true;
        
        @SuppressWarnings("unused")
		int ticks = 0;
        @SuppressWarnings("unused")
        int frames = 0;
        
        long frameCounter = 0;
        
        double delta = 0;
        
        long startTime;
        long passedTime;
        long lastTime = System.nanoTime();
        double unprocessedTime = 0;
        boolean render = false;
        
        /*
         * game loop
         */
        while (running) {
            
        	/*
        	 * Calculates passed time to set when to render and tick.
        	 */
            startTime = System.nanoTime();
            passedTime = startTime - lastTime;
            lastTime = startTime;
            
            unprocessedTime += passedTime / 1000000000.0;
            frameCounter += passedTime;
            

            /*
             * controls the ticking
             */
            delta += passedTime / ns;
            while (delta >= 1) {
                tick();	
                ticks++;
                delta--;
            }
            
            if (frameCounter >= 1000000000L) {
//                System.out.println(frames + " fps, " + ticks + "ups");
                frames = 0;
                frameCounter = 0;
                ticks = 0;
            }
            
            /*
             * controls the rendering
             */
            render = false;
            while (unprocessedTime > frameTime) {
                render = true;
                unprocessedTime -= frameTime;
            }

            if (render) {
                renderImage();
                frames++;
            } else {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        System.exit(0);
    }
    
    /**
     * Renders the tiles(map) and all drawables into the world image.
     */
    private void render() {
    	Graphics g = image.createGraphics();
    	
    	g.setColor(Color.BLACK);
    	g.fillRect(0, 0, WIDTH, HEIGHT);
    	
//    	renderTiles(g);
    	TileRenderer.renderTiles(g, new Vector2(mapPos), getWidth(), getHeight());
    	for (int i = drawables.size() - 1; i >= 0 ; i--) {
    		if(!drawables.get(i).removed()) {
    			drawables.get(i).render(g);
    		} else {
    			drawables.remove(i);
    		}
        }
    	renderMinimap(g);
    }
    
    /**
     * Renders the world image into the canvas using a triple buffer.
     */
    private void renderImage() {
    	bs = getBufferStrategy();
    	if (bs == null) {
    		createBufferStrategy(3);
    		return;
    	}
    	
    	render();
    	
    	Graphics g = bs.getDrawGraphics();
    	g.setColor(Color.BLACK);
    	g.fillRect(0, 0, getWidth(), getHeight());
    	g.drawImage(image, 0, 0, null);
    	g.dispose();
        bs.show();
    }
    
    /**
     * Handles the logic of the minimap and the tickables and the input.
     */
    private void tick() {
    	checkKeys();
    	checkMouse();
    	
    	stdDDmenu.select((int)Mouse.getPos().x, (int)Mouse.getPos().y);
    	
        moveView();
        minimapMove();
        moveViewMouse();
        mode.tick();
        
        zoom();
        
    	for (int i = tickables.size() - 1; i >= 0 ; i--) {
    		if(!tickables.get(i).removed()) {
    			tickables.get(i).tick();
    		} else {
    			tickables.remove(i);
    		}
        }
    }
    
    /**
     * Renders the minimap and robots with the viewing angle into it.
     * 
     * @param g Graphics object used to render the minimap.
     */
    private void renderMinimap(Graphics g) {
    	Graphics2D g2d = (Graphics2D) g;
    	g2d.scale(scale, scale);
    	g.setColor(Color.BLACK);
    	g.drawImage(originalMinimapImage, (int) minimapPos.x, (int) minimapPos.y, null);
    	
    	for (int i = drawables.size() - 1; i >= 0 ; i--) {
        	Drawable drawable = drawables.get(i);
    		if(!drawable.removed()) {
    			if (drawable instanceof Robot) {
	    			int drawableX = (int) (drawable.getPos().x * Main.zoom / Tile.size);
	    			int drawableY = (int) (drawable.getPos().y * Main.zoom / Tile.size);
	    			g.setColor(drawable.getColor());
	    			g.fillRect(drawableX + (int) ((minimapPos.x * Main.zoom) - 3), drawableY + (int) ((minimapPos.y * Main.zoom) - 3), 
    							6, 6);
    				double angle = ((Robot) drawable).getAngle();
    				int xDir = 0;
    				int yDir = 0;
    				
    				xDir = -(int)(Math.cos(angle + Math.PI * 0.5) * 5);
    				yDir = -(int)(Math.sin(angle + Math.PI * 0.5) * 5);
    				
    				g.setColor(Color.BLACK);
    				g.drawLine(drawableX + (int) minimapPos.x, drawableY + (int) minimapPos.y, 
        					drawableX + (int) minimapPos.x + xDir, drawableY + (int) minimapPos.y + yDir);
    			}
    		} else {
    			drawables.remove(i);
    		}
        }
    	
        int x = (int) mapPos.x / Tile.START_SIZE + (int) minimapPos.x;
        int y = (int) mapPos.y / Tile.START_SIZE + (int) minimapPos.y;
        g.drawRect(x, y, WIDTH / Tile.size, HEIGHT / Tile.size + 1);
    }
    
    /**
     * Loads the colors of the map image into the tiles array.
     * 
     * @param path Path of the map image.
     */
    private void loadMap(String path) {
        originalMinimapImage = imageLoader.load(path);
        worldWidth = originalMinimapImage.getWidth();
        worldHeight = originalMinimapImage.getHeight();
        int[] tiles = new int[worldWidth * worldHeight];
        originalMinimapImage.getRGB(0, 0, worldWidth, worldHeight, tiles, 0, worldWidth);
        TileRenderer.addTileColors(tiles);
    }
    
    /**
     * Moving the position of the viewer camera in the world with a given speed (keyboard).
     */
    private void moveView() {
//		System.out.println(selectedRobot);
    	if (selectedRobot == -1) {
            float dx = 8f;
            float dy = 8f;
            if (mapPos.x - dx >= 0) {
                if (left) mapPos.x -= dx;
            }
            if (mapPos.y - dy >= 0) {
                if (up) mapPos.y -= dy;
            }
            if (mapPos.x + dx + WIDTH <= worldWidth * Tile.size) {
                if (right) mapPos.x += dx;
            }
            if (mapPos.y + dy + HEIGHT <= worldHeight * Tile.size) {
                if (down) mapPos.y += dy;
            }
    	}
    }
    
    /**
     * Moving the position of the viewer camera in the world with dragging the mouse in the world.
     */
    private void moveViewMouse() {
        if (mouseDown && !mouseDownMinimap) {
            int dx = (int) (Mouse.lastPos().x - Mouse.getPos().x);
            int dy = (int) (Mouse.lastPos().y - Mouse.getPos().y);
            if (dx != 0 || dy != 0) {
            	Mouse.lastPos().x = Mouse.getPos().x;
            	Mouse.lastPos().y = Mouse.getPos().y;
                mapPos.x += dx / Main.zoom;
                mapPos.y += dy / Main.zoom;
                if (mapPos.x < 0) mapPos.x = 0;
                if (mapPos.x + WIDTH / Main.zoom > worldWidth * Tile.START_SIZE) mapPos.x = worldWidth * Tile.START_SIZE - WIDTH / Main.zoom;
                if (mapPos.y < 0) mapPos.y = 0;
                if (mapPos.y + HEIGHT / Main.zoom > worldHeight * Tile.START_SIZE) mapPos.y = worldHeight * Tile.START_SIZE - HEIGHT / Main.zoom;
                mouseDownMap = true;
            }
        }
    }
    
    /**
     * Moving the position of the viewer camera in the world with dragging the mouse in the minimap.
     */
    private void minimapMove() {
        if (mouseDown && !mouseDownMap && Mouse.getPos().x > minimapPos.x * scale && Mouse.getPos().x < worldWidth * scale + minimapPos.x * scale) {
            if (Mouse.getPos().y > minimapPos.y * scale && Mouse.getPos().y < worldHeight * scale + minimapPos.y * scale) {
                mapPos.x = (Mouse.getPos().x - 1) / scale * Tile.START_SIZE - WIDTH / 2;
                mapPos.y = (Mouse.getPos().y - 1) / scale * Tile.START_SIZE - HEIGHT / 2;
                
                if (mapPos.x < 0) {
                    mapPos.x = 0;
                }
                if (mapPos.y < 0) {
                    mapPos.y = 0;
                }
                if (mapPos.x > worldWidth * Tile.START_SIZE - WIDTH) {
                    mapPos.x = worldWidth * Tile.START_SIZE - WIDTH;
                }
                if (mapPos.y > worldHeight * Tile.START_SIZE - HEIGHT) {
                    mapPos.y = worldHeight * Tile.START_SIZE - HEIGHT;
                }
                mouseDownMinimap = true;
            }
        }
    }
    
    /**
     * Returns if the given Position is in the world of the Game.
     * 
     * @author ruben.ortlam
     * @param pos The Position to be checked.
     * @return true if the position is in the World, false otherwise.
     */
    public static boolean isInWorld(Vector2 pos) {
    	if(pos.x >= 0 && pos.y >= 0 && pos.x < worldWidth * Tile.size && pos.y < worldWidth * Tile.size) {
    		return true;
    	}
    	return false;
    }
    
    /**
     * @author robert.kraneis
     */
    public static Damageable entityCollision(Tickable tickable, Vector2 pos) {
    	for (Tickable tick : Main.getTickables()) {
			if (tick instanceof Damageable && tick.getPos() != null && tick.getSize() != null && tick != tickable) {
				if (tick.getPos().distance(pos) <
						tick.getSize().length() / 2 + tickable.getSize().length() / 2) {
					// System.out.println(tick.getPos().distance(tickable.getPos()) + ":" + 
					// 				   tick.getSize().length() / 2 + tickable.getSize().length() / 2);
					return (Damageable)tick;
				}
			}
		}
    	
    	return null;
    }
    
    /**
     * @author robert.kraneis
     */
    public static int entityExplosionCollision(Vector2 pos, double radius, int damage) {
    	int victims = 0;
    	
    	for (Tickable tick : Main.getTickables()) {
			if (tick instanceof Damageable && tick.getPos() != null && tick.getSize() != null) {
				if (tick.getPos().distance(pos) <
						tick.getSize().length() / 2 + radius) {
					
					((Damageable)tick).damage(damage);
					
					victims++;
				}
			}
		}
    	
    	return victims;
    }
    
    /**
     * Sets the id of the clicked robot.
     * @param mousePos
     */
    public void selectRobot(Vector2 mousePos) {
    	if (!mouseDown) {
        	Tickable tickable;
        	
        	selectedRobot = -1;
        	for (int i = tickables.size() - 1; i >= 0 ; i--) {
        		tickable = tickables.get(i);
        		if(!tickable.removed()) {
        			if (tickable instanceof Robot) {
            			Vector2 pos = tickable.getPos();
            			Vector2 size = tickable.getSize();
            			if (pos.x - size.x / 2 < mousePos.x && pos.x + size.x / 2 > mousePos.x &&
            					pos.y - size.y / 2 < mousePos.y && pos.y + size.y / 2 > mousePos.y) {
            				selectedRobot = tickable.getID();
//            				((Robot)tickable).damage(1000);
            			}
        			}
        		} else {
        			tickables.remove(tickable);
        		}
            }
    	}
    }
    
    /**
     * Bugged world zoom.
     */
//    private void zoom(MouseWheelEvent e) {
//        float scaleFactor = 0.03f;
//        scale -= e.getWheelRotation() * scaleFactor;
//        if (WIDTH / (Tile.START_SIZE * scale) <= worldWidth || HEIGHT / (Tile.START_SIZE * scale) <= worldHeight) {
//            Tile.size = (int) (Tile.START_SIZE * scale);
//            mapPos.x -= (WIDTH / 2) * (e.getWheelRotation() * scaleFactor);
//            mapPos.y -= (HEIGHT / 2) * (e.getWheelRotation() * scaleFactor);
////            System.out.println((WIDTH / 2) * (e.getWheelRotation() * scaleFactor));
//            System.out.println(mapPos);
//            if (mapPos.x < 0) mapPos.x = 0;
////            if (mapPos.x - WIDTH > WIDTH / (Tile.size));
//            if (mapPos.y < 0) mapPos.y = 0;
////            if (mapPos.y - HEIGHT > HEIGHT / (Tile.size));
//        } else {
//            scale += e.getWheelRotation() * scaleFactor;
//        }
//    }
    
    private void zoom() {
    	int rotation = Mouse.getMouseWheelRotation();
    	if(rotation != 0) {
    		zoom -= rotation * 0.03;
//    		System.out.println(zoom);
    	}
    }
    
    /**
     * Adds a drawable to drawables(ArrayList).
     * 
     * @param drawable An instance of Drawable.
     */
    public static void addDrawable(Drawable drawable) {
        drawables.add(drawable);
    }
    
    /**
     * Adds a tickable to tickables(ArrayList).
     * 
     * @param tickable An instance of Tickable.
     */
    public static void addTickable(Tickable tickable) {
        tickables.add(tickable);
    }
    
    /**
     * Removes a dawable from drawables.
     * 
     * @param drawable Drawable to remove.
     */
    public static void removeDrawable(Drawable drawable) {
        drawables.remove(drawable);
    }
    
    /**
     * Removes a tickable from tickables.
     * 
     * @param tickable Tickable to remove.
     */
    public static void removeTickable(Tickable tickable) {
        tickables.remove(tickable);
    }
    
    /**
     * @return Returns the tickables ArrayList.
     */
    public static ArrayList<Tickable> getTickables() {
    	return tickables;
    }
    
    /**
     * @return Returns the drawables ArrayList.
     */
    public static ArrayList<Drawable> getDrawables() {
    	return drawables;
    }
    
    /**
     * Sets how many frames per second should be rendered.
     * 
     * @param Number of frames per second to set.
     */
    public void setFPS(int fps) {
    	FRAME_CAP = fps;
        frameTime = 1.0 / FRAME_CAP;
    }
    
    /**
     * Sets how many ticks per second should be done.
     * 
     * @param Number of ticks per second to set.
     */
    public void setTPS(int tps) {
    	UPDATE_CAP = tps;
        ns = 1000000000.0 / UPDATE_CAP;
    }
    
    public void checkKeys() {
    	int sizeX;
    	int sizeY;
    	
    	if (Keyboard.keysDown[KeyEvent.VK_ESCAPE]) running = false;
    	if (Keyboard.keysDown[KeyEvent.VK_UP] || Keyboard.keysDown[KeyEvent.VK_W]) {
    		up = true;
    	} else {
    		up = false;
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_DOWN] || Keyboard.keysDown[KeyEvent.VK_S]) {
    		down = true;
    	} else {
    		down = false;
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_LEFT] || Keyboard.keysDown[KeyEvent.VK_A]) {
    		left = true;
    	} else {
    		left = false;
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_RIGHT] || Keyboard.keysDown[KeyEvent.VK_D]) {
    		right = true;
    	} else {
    		right = false;
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_PLUS] || Keyboard.keysDown[NUM_PLUS]) {
            scale += 0.1;
        	sizeX = (int) (scale * (worldWidth + minimapPos.x));
        	sizeY = (int) (scale * (worldHeight + minimapPos.y));
        	if (sizeX > worldWidth * 2 || sizeY > worldHeight * 2) scale -= 0.1;
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_MINUS] || Keyboard.keysDown[NUM_MINUS]) {
    		if (scale > 0.1) {
                scale -= 0.1;
            	sizeX = (int) (scale * (worldWidth + minimapPos.x));
            	sizeY = (int) (scale * (worldHeight + minimapPos.y));
            	if (sizeX < worldWidth / 2 || sizeY < worldHeight / 2) scale += 0.1;
            }
    	}
    	if (Keyboard.keysDown[KeyEvent.VK_R]) scale = 1;
    }
    
    /**
     * Handles mouse input in the main class.
     */
    public void checkMouse() {
    	if (Mouse.mouseDragged[MouseEvent.BUTTON1]) {
    		mouseDown = true;
    	}
    	if (Mouse.mousePressed[MouseEvent.BUTTON1]) {
    		selectRobot(new Vector2(Mouse.getPos().x + mapPos.x, Mouse.getPos().y + mapPos.y));
    		mouseDown = true;
    		
    		stdDDmenu.trigger();
    	}
    	if (Mouse.mousePressed[MouseEvent.BUTTON3]) {
    		stdDDmenu.open((int)Mouse.getPos().x, (int)Mouse.getPos().y);
    	}
    	if (Mouse.released()) {
    		mouseDown = false;
    		mouseDownMinimap = false;
    		mouseDownMap = false;
    	}
    }
    
}
